<?php

namespace Alipay\aop\request\alipay;

use Yii;
use yii\helpers\Json;

/**
 * ALIPAY TRADE API
 * @author auto create
 * @since 1.0, 2018-06-14 17:35:00
 */
class TradeRequest extends \yii\base\Component {

    /**
     * APP支付接口2.0
     */
    const REQUEST_APP_PAY = 'alipay.trade.app.pay';

    /**
     * 统一收单交易撤销接口
     */
    const REQUEST_CANCEL = 'alipay.trade.cancel';

    /**
     * 统一收单交易关闭接口
     */
    const REQUEST_CLOSE = 'alipay.trade.close';

    /**
     * 统一收单报关接口
     */
    const REQUEST_CUSTOMS_DECLARE = 'alipay.trade.customs.declare';

    /**
     * 查询报关详细信息
     */
    const REQUEST_CUSTOMS_QUERY = 'alipay.trade.customs.query';

    /**
     * 商户可使用该接口查询自已通过alipay.trade.refund提交的退款请求是否执行成功。
     */
    const REQUEST_FASTPAY_REFUND_QUERY = 'alipay.trade.fastpay.refund.query';

    /**
     * 统一收单交易结算接口
     */
    const REQUEST_ORDER_SETTLE = 'alipay.trade.order.settle';

    /**
     * 统一收单下单并支付页面接口
     */
    const REQUEST_PAGE_PAY = 'alipay.trade.page.pay';

    /**
     * 用于在线下场景交易一次创建并支付掉
     * 修改路由策略到R
     */
    const REQUEST_PAY = 'alipay.trade.pay';

    /**
     * 收银员通过收银台或商户后台调用支付宝接口，生成二维码后，展示给伤脑筋户，由用户扫描二维码完成订单支付。
     * 修改路由策略到R
     */
    const REQUEST_PRECREATE = 'alipay.trade.precreate';

    /**
     * 统一收单线下交易查询
     * 修改路由策略到R
     */
    const REQUEST_QUERY = 'alipay.trade.query';

    /**
     * 统一收单交易退款接口
     */
    const REQUEST_REFUND = 'alipay.trade.refund';

    /**
     * 厂商支付授权时上传设备数据接口，目前主要包含三星支付。com
     */
    const REQUEST_VENDORPAY_DEVICEDATA_UPLOAD = 'alipay.trade.vendorpay.devicedata.upload';

    /**
     * 手机网站支付接口2.0
     */
    const REQUEST_WAPPAY = 'alipay.trade.wap.pay';

    /**
     * 商户通过该接口进行交易的创建下单
     */
    const REQUEST_CREATE = 'alipay.trade.create';

    /**
     * 商户通过该接口进行交易的创建下单
     */
    private $apiMethodName = null;
    private $bizContent;
    private $apiParas = [];
    private $terminalType;
    private $terminalInfo;
    private $prodCode;
    private $apiVersion = "1.0";
    private $notifyUrl;
    private $returnUrl;
    private $needEncrypt = false;

    public function __construct($name, $config = array()) {
        $this->setApiMethodName($name);
        parent::__construct($config);
    }

    /**
     * Initializes the object.
     * This method is invoked at the end of the constructor after the object is initialized with the
     * given configuration.
     */
    public function init() {
        if ($this->apiMethodName == null) {
            throw new \yii\base\NotSupportedException('Api not supported.');
        }
    }

    public function setBizContent($bizContent) {
        if (is_array($bizContent) && !empty($bizContent)) {
            $bizContent = Json::encode($bizContent);
        }
        $this->bizContent = $bizContent;
        $this->apiParas["biz_content"] = $bizContent;
    }

    public function getApiMethodName() {
        return $this->apiMethodName;
    }

    public function setApiMethodName($name) {
        $this->apiMethodName = $name;
    }

    public function getBizContent() {
        return $this->bizContent;
    }

    public function setNotifyUrl($notifyUrl) {
        $this->notifyUrl = $notifyUrl;
    }

    public function getNotifyUrl() {
        return $this->notifyUrl;
    }

    public function setReturnUrl($returnUrl) {
        $this->returnUrl = $returnUrl;
    }

    public function getReturnUrl() {
        return $this->returnUrl;
    }

    public function getApiParas() {
        return $this->apiParas;
    }

    public function getTerminalType() {
        return $this->terminalType;
    }

    public function setTerminalType($terminalType) {
        $this->terminalType = $terminalType;
    }

    public function getTerminalInfo() {
        return $this->terminalInfo;
    }

    public function setTerminalInfo($terminalInfo) {
        $this->terminalInfo = $terminalInfo;
    }

    public function getProdCode() {
        return $this->prodCode;
    }

    public function setProdCode($prodCode) {
        $this->prodCode = $prodCode;
    }

    public function setApiVersion($apiVersion) {
        $this->apiVersion = $apiVersion;
    }

    public function getApiVersion() {
        return $this->apiVersion;
    }

    public function setNeedEncrypt($needEncrypt) {

        $this->needEncrypt = $needEncrypt;
    }

    public function getNeedEncrypt() {
        return $this->needEncrypt;
    }

}
